﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Web;
using WLFramework.Json;
using GenericHtml;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getPositionRole 的摘要说明
    /// </summary>
    public class getPositionRole : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int? pid = context.GetValueByName<int?>("P_ID");
            if (pid == null)
                return;

            using (var db = new PermissionContext())
            {
                var posirole = db.View_PositionRole.Where(k => k.P_ID == pid);

                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = posirole.Count(),
                    rows = posirole.Select(k => new
                    {
                        P_ID = k.P_ID,
                        R_State = k.R_State == 0 ? "禁用" : "启用",
                        R_ID = k.R_ID,
                        R_CName = k.R_CName,
                        R_EName = k.R_EName,
                        R_Description = k.R_Description
                    }).ToList()
                }));
            }
        }
    }
}